define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sub_order/index' + location.search,
                    add_url: 'sub_order/add',
                    edit_url: 'sub_order/edit',
                    del_url: 'sub_order/del',
                    multi_url: 'sub_order/multi',
                    table: 'sub_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'parent_id', title: __('Parent_id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user.username', title: __('User.username')},
                        {field: 'driver_id', title: __('Driver_id')},
                        {field: 'driverinfo.name', title: __('Driverinfo.name')},
                        {field: 'order_sn', title: __('Order_sn')},
                        {field: 'type', title: __('Type'), searchList: {"monopoly":__('Type monopoly'),"share":__('Type share'),"cargo":__('Type cargo')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"1":__('status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('Status 6'),"7":__('Status 7'),"8":__('Status 8'),"10":__('Status 10')}, formatter: Table.api.formatter.status},
                        {field: 'pay_status', title: '支付状态', searchList: {"0":"未支付","1":"已支付","2":"后台设置已支付","3":"0元订单"}, formatter: Table.api.formatter.status},
                        {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'coupon_price', title: __('Coupon_price'), operate:'BETWEEN'},
                        {field: 'pay_price', title: __('Pay_price'), operate:'BETWEEN'},
                        {field: 'passenger.person', title: __('Passenger.adult')},
                        {field: 'passenger.tips', title: __('Passenger.tips'), operate:'BETWEEN'},
                        {field: 'passenger.luggage_type', title: __('Passenger.luggage_type')},
                        {field: 'passenger.luggage_weight', title: __('Passenger.luggage_weight'), operate:'BETWEEN'},
                        {field: 'passenger.pet_name', title: __('Passenger.pet_name')},
                        {field: 'passenger.pet_weight', title: __('Passenger.pet_weight'), operate:'BETWEEN'},
                        {field: 'cargo.name', title: __('Cargo.name')},
                        {field: 'cargo.type', title: __('Cargo.type')},
                        {field: 'cargo.weight', title: __('Cargo.weight'), operate:'BETWEEN'},
                        {field: 'cargo.packed', title: __('Cargo.packed')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});